<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<jsp:include page="/common/link.jsp"></jsp:include>
<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
<%@include file="/WEB-INF/ibnms/common/ztree.jsp" %>
<html style="height:100%;overflow:hidden;">
	<head>
		<title>
		</title>
		<s:set id="type" value="#parameters.type[0]"/>
	</head>
	
	<script type="text/javascript">
		var $layout = $("#layout");
		var $zTreeObj;
		$(document).ready(function(){
			$zTreeObj = $.fn.zTree.init($("#moduleManageTree"), 
			{	
				treeId:"id",
				data: {
					key:{
                           name:'name',
                           title:'name',
                           id:'id'
                       },
                       simpleData:{
                           idKey:'id'
                       }				
				},
				check:{
					enable:true,
					autoCheckTrigger:true,
					chkboxType:{ "Y": "sp", "N": "sp" }
				},
				async:{
					enable:true,
					type:"post",
					dataType:"json",
					autoParam:["id=node.id"],
					url:"getSubSystemModuleJson.do"
				}, 
				view: {
					fontCss: function (treeId, treeNode) {
						return (!!treeNode.highlight) ? {color:"#A60000", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"};
					},
					dblClickExpand:true
				},
				callback:{
					onNodeCreated:function(event, treeId, treeNode){
						if(treeNode.pId == null || treeNode.pId == 'null'){
							treeNode.pId = 'moduleTree';
						}
						return treeNode;
					},
					onAsyncSuccess:function(event, treeId, treeNode, msg){
						treeNode.pId='roleTree';
						/*if(msg[0].pId==null||msg[0].pId=='null'){
							var firstNode = $zTreeObj.getNodeByParam('id',msg[0].id,null);
							$(firstNode).click();
							$zTreeObj.selectNode(firstNode,false);
						}*/
						return treeNode;
					}
				}
			}, 
			 [
				{"name":"模块管理", id:"0" ,pId:"0"}
			]);
		});
		
		$.ajax({
			type:"post",
			url:"getSubSystemModuleJson.do",
			data: "node.id=0",
			dataType:"json",
			success:function(msg){
				var rootNodeObj = $zTreeObj.getNodeByParam("id","0",null);
				$zTreeObj.addNodes(rootNodeObj,msg,false);
				var nodeName = encodeURI(encodeURI($(rootNodeObj).attr("name")));
				$("iframe[name='roleDisplayFrame']").attr("src","loadListModules.do?theForm.PARENT_ID=0&theForm.MODULE_LEVEL=0&type=${type}");
				$zTreeObj.selectNode(rootNodeObj,false);
			}
		});
		
		$("#selecter").click(function(){
				// 获取所有被选中的模块节点
				var checkNodes = $moduleTreeObj.getCheckedNodes(true);
				if(checkNodes.length==0){
					alert("请选择模块");
					return;
				}
				var cfgNodeIds = "";
				$.each(checkNodes,function(idx,node){
					cfgNodeIds += $(node).attr("id") + ",";
				})
				if(cfgNodeIds.length>0){
					cfgNodeIds = cfgNodeIds.subString(0,cfgNodeIds.length-1);
				}
				
				parent.window.returnValue=cfgNodeIds;
				parent.window.close();
				self.close();
		});
	</script>
<body style="height:100%;">
	<div class="easyui-layout" id="layout" >
		<div data-options="region:'center',fit:false,split:false,minWidth:100" style="width:200px">
			<ul id="moduleManageTree" class="ztree" style="width:95%; height:98%; overflow:auto;"></ul>
		</div>
	</div>
	
	
	<div class="easyui-layout" id="layout" style="width:100%;height:100%" >
		<div data-options="region:'south'" style="width:100%;height:60px;overflow:hidden;padding-left:0px;padding-top:0px;">
			<input id="selecter" type="button" class="btn-style02" align="middle" value="确定" />
		</div>
		<div data-options="region:'center',title:''" style="width:95%;border-right: 0px;overflow-x:hidden;overflow-y:hidden">
			<ul id="moduleManageTree" class="ztree" style="width:95%; height:98%; overflow:auto;"></ul>
		</div>
	</div>
</body>
</html>
